﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Map_Creator.XNA
{
    public class XnaGraphics : SpriteBatch
    {
        private Texture2D WhiteTexture;

        public XnaGraphics(GraphicsDevice graphicsDevice) : base(graphicsDevice)
        {
            WhiteTexture = new Texture2D(GraphicsDevice,1,1);
            WhiteTexture.SetData(new Color[]{Color.White});
        }

        public void DrawLine(Vector2 start, Vector2 end, Color color)
        {
            var length = (end - start).Length();
            var rotation = (float) Math.Atan2(end.Y - start.Y, end.X - start.X);
            Draw(WhiteTexture,start,null,color,rotation,Vector2.Zero,new Vector2(length,1), SpriteEffects.None,0);
        }

        public void DrawRectangle(Rectangle rectangle, Color color)
        {
            Draw(WhiteTexture, new Rectangle(rectangle.Left, rectangle.Top, rectangle.Width, 1), color);
            Draw(WhiteTexture, new Rectangle(rectangle.Left, rectangle.Bottom, rectangle.Width, 1), color);
            Draw(WhiteTexture, new Rectangle(rectangle.Left, rectangle.Top, 1, rectangle.Height), color);
            Draw(WhiteTexture, new Rectangle(rectangle.Right, rectangle.Top, 1, rectangle.Height + 1), color);
        }

        public void FillRectangle(Rectangle rectangle, Color color)
        {
            Draw(WhiteTexture,rectangle,color);
        }
    }
}
